package com.red.wood.dubbo.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.red.wood.common.util.CommonUtils;
import com.red.wood.dubbo.dao.CdnBusinessDataDao;
import com.red.wood.dubbo.service.CdnBusinessDataService;
import com.red.wood.dubbo.util.ProvinceParse;
import com.red.wood.dubbo.util.ReadIPFile;

@Service
public class CdnBusinessDataServiceImpl implements CdnBusinessDataService{

	private static final Log log = LogFactory.getLog(CdnBusinessDataServiceImpl.class);
	
	@Autowired
	private CdnBusinessDataDao dao;

	@Override
	public List<Map<String, Object>> getCdnDataInfo() {
		List<Map<String, Object>> list = dao.getCdnDataInfo();
		if(list != null && list.size() > 0) {
			for(Map<String,Object> map : list) {
				String cdnAdd = CommonUtils.valueOf(map.get("CDNADD"));
				String province = ProvinceParse.addressAdscription(cdnAdd);
				map.put("PROVINCE",province);
			}
		}
		return list;
	}

	@Override
	public List<Map<String, Object>> getCdnNetInfo(int min, int max) {
		return dao.getCdnNetInfo(min,max);
	}

	@Override
	public List<Map<String, Object>> getCdnIpInfo(int min,int max) {
		List<Map<String,Object>> list = null;
		try {
			list = dao.getCdnIpInfo(min,max);
			if(list != null && list.size() > 0) {
				for(Map<String,Object> map : list) {
					String startIp = CommonUtils.valueOf(map.get("STARTIP"));
					String[] area = ReadIPFile.getInstance().find(startIp);
					map.put("PROVINCE",area[1]);
				}
			}
		}catch(Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
		}
		return list;
	}

	@Override
	public List<Map<String, Object>> getCdnCustomerInfo(int min,int max) {
		List<Map<String,Object>> list = dao.getCdnCustomerInfo(min,max);
		if(list != null && list.size() > 0) {
			for(Map<String,Object> map : list) {
				String address = CommonUtils.valueOf(map.get("ADDRESS"));
				String province = ProvinceParse.addressAdscription(address);
				map.put("PROVINCE",province);
			}
		}
		return list;
	}

	@Override
	public List<Map<String, Object>> getCdnDomainInfo(int min,int max) {
		return dao.getCdnDomainInfo(min, max);
	}

	@Override
	public List<Map<String, Object>> getCdnHouseInfo(int min, int max) {
		List<Map<String,Object>> list = dao.getCdnHouseInfo(min,max);
		return list;
	}

	@Override
	public List<Map<String, Object>> getCdnNodeInfo(int min,int max) {
		return dao.getCdnNodeInfo(min, max);
	}

	@Override
	public List<Map<String, Object>> getCdnLinkOfficerInfo() {
		return dao.getCdnLinkOfficerInfo();
	}

	@Override
	public List<Map<String, Object>> getCdnGetWayInfo(int min,int max) {
		return dao.getCdnGetWayInfo(min, max);
	}
}
